Kotlin Koans 01 Hello, world!

Contents

Simple Functions (Playground)

Description

Take a look at function syntax and make the function start return the string "OK".

In the tasks the function TODO() is used that throws an exception. Your job during the koans will be to replace this function invocation with a meaningful code according to the problem.

関数構文を見て、 "OK"を返すstart関数を実装してください。

タスクでは、例外をthrowするTODO()関数が使用されます。Koansでは、このTODO()関数呼び出しを、問題に応じた意味のあるコードに書き換えていきます。

Code

fun start(): String = "OK"

Memo

  • 単一式関数
    • 関数が1つの式である場合{}を省略できる。
    • 戻り値の型推論が可能である場合は、戻り値の型を省略できる。
fun start() = "OK"

Kotlinにおいて「関数は第一級オブジェクト」ということを言いたい。のだと思う。

← Posts